package org.fjala.softure.tree;

import java.util.Collection;

/**
 * Collection that manage data as a tree. The tree structure is a set of linked
 * nodes that cannot contain duplicate nodes.
 *
 * @author Dann Meneses
 *
 * @param <E> The type of elements in this tree
 */
public interface Tree<E> extends Collection<E> {

    /**
     * Replaces the node
     * <code>oldNode</code> with the node
     * <code>newNode</code>.
     *
     * @param oldElement Node to be replaced.
     * @param newElement New node to replace the old one.
     */
    void replace(E oldElement, E newElement);

    /**
     * Returns the root of the tree. Returns
     * <code>null</code> only if the tree has no nodes.
     *
     * @return The root of the tree.
     */
    Node<E> getRoot();

    /**
     * Inserts the node
     * <code>newNode</code> in the child list of
     * <code>parent</code>.
     *
     * @param parent Parent node to insert the element.
     * @param element Element to insert.
     *
     * @return True if the element was added successfully to the tree.
     */
    boolean add(Node<E> parent, E element);
}